package com.gusto.engine.semsim.measures.impl;

import org.apache.log4j.Logger;

import uk.ac.shef.wit.simmetrics.similaritymetrics.JaroWinkler;

import com.gusto.engine.semsim.exceptions.SimilarityException;
import com.gusto.engine.semsim.measures.ValueSimilarity;

/**
 * <p>JaroWinkler is a String similarity measure,
 * it uses the number of transposition to get equal strings.</p>
 * 
 * @author amokrane.belloui@gmail.com
 */
public class JaroWinklerStringSimilarity implements ValueSimilarity {
	
	private Logger log = Logger.getLogger(getClass());
	
	public String getId() {
		String id = "[" + getClass().getName() + "]";
		return id;
	}
	
	public Double getSimilarity(Object value1, Object value2) throws SimilarityException {
		JaroWinkler jw = new JaroWinkler();
		Double sim = new Double(jw.getSimilarity((String)value1, (String)value2));
		
		
		if (sim.isInfinite() || sim.isNaN()) {
			log.info("Jaro Winkler " + value1 + " " + value2 + " " + sim + ", returning 0.0 ");
			return 0.0;
		}
		log.info("Jaro Winkler " + value1 + " " + value2 + " " + sim);
		return sim;
	}
	
}
